//
//  WMEPlayerViewController.m
//  WMEMusic
//
//  Created by 恩叔 on 16/4/28.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEPlayerViewController.h"
#import "WMEPlayerView.h"
#import "NetwrokHandler.h"
#import "WMEDonut.h"
#import "UIView+hhhh.h"
#import "WMEPlayerModel.h"
#import "NSString+WMEFormatTimer.h"
#import "WMELyTableViewCell.h"
#import <AVFoundation/AVFoundation.h>

@interface WMEPlayerViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UIButton *next;
@property (nonatomic, strong)UIButton *previous;

@property (nonatomic, strong)UIImageView *cover;
@property (nonatomic, strong)UITableView *songList;
@property (nonatomic, strong)UITableView *lyTableView;
@property (nonatomic, strong)UIScrollView *scrollView;

@property (nonatomic, strong)UISlider *shijian;
@property (nonatomic, strong)UILabel *beginLabel;
@property (nonatomic, strong)UILabel *endLabel;

@property (nonatomic, strong)NSMutableArray *dataArr;
@property (nonatomic, strong)WMEPlayerModel *model;

@property (nonatomic, assign)NSInteger newIndex;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UILabel *authorLabel;
@property (nonatomic, strong)UIButton *playStyle;

@property (nonatomic, strong)NSMutableArray *timerArray;
@property (nonatomic, strong)NSMutableArray *lyricArray;

@property (nonatomic,assign)BOOL have;
@end
//static BOOL playing;
@implementation WMEPlayerViewController

//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        static WMEPlayerViewController *playVC= nil;
//        static dispatch_once_t onceToken;
//        dispatch_once(&onceToken, ^{
//            playVC = [[WMEPlayerViewController alloc] init];
//        });
//    }
//    return self;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    //当路线改变时会发送通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRouterChange:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
    //AVAudioSessionInterruptionNotification
    //声音会话中断 通知
    //如电话,或推送 都会改变他
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
    // Do any additional setup after loading the view.
//    WS(ws);
//    static NSInteger newIndex = self.index;;
    self.lyricArray = [NSMutableArray array];
    self.timerArray = [NSMutableArray array];
    self.dataArr = [NSMutableArray array];
    self.view.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];

    for (WMEPlayerModel *model in self.listArr) {
        NSString *str = model.file_link;
        [_dataArr addObject:str];
    }
    [self musicModelRequest:self.str];
    _newIndex = _index;
    ES_DefaultManager.playToEndBlock = ^(){
        
        NSInteger playStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"playStyle"];
        if (playStyle == 1) {
            if (_newIndex + 1 == _songArr.count) {
                _newIndex = 0;
            }else {
                _newIndex++;
            }
            WMESongListModel *smodel = _songArr[_newIndex];
            NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
            [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
                NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
                NSString *strURL = result[@"songinfo"][@"lrclink"];
                [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                    self.str = resultw;
                    [self musicModelRequest:self.str];
                    NSMutableArray *newArr = [NSMutableArray array];
                    for (WMEPlayerModel *model in arr) {
                        NSString *str = model.file_link;
                        [newArr addObject:str];
                    }
                    [self musicModelRequest:resultw];
                    [self.lyTableView reloadData];
                    self.lyTableView.contentOffset = CGPointMake(0, 0);
                    [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                    if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                    }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                    }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                    }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                    }else {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }
                    _titleLabel.text = result[@"songinfo"][@"title"];
                    _authorLabel.text = result[@"songinfo"][@"author"];
                }];
            } failure:^(NSError *error) {
                NSLog(@"网络请求错误");
            }];
        }else if(playStyle == 2){
            _index = [self randomIndex];
            WMESongListModel *smodel = _songArr[_index];
            NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
            [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
                NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
                NSString *strURL = result[@"songinfo"][@"lrclink"];
                [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                    
                    self.str = resultw;
                    NSMutableArray *newArr = [NSMutableArray array];
                    for (WMEPlayerModel *model in arr) {
                        NSString *str = model.file_link;
                        [newArr addObject:str];
                    }
                    [self musicModelRequest:self.str];
                    [self.lyTableView reloadData];
                    self.lyTableView.contentOffset = CGPointMake(0, 0);
                    [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                    WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                    [manager downLoadWithBlock:^(BOOL have) {
                        _have = have;
                    } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                    if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                    }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                    }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                    }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                    }else {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }
                    _titleLabel.text = result[@"songinfo"][@"title"];
                    _authorLabel.text = result[@"songinfo"][@"author"];
                }];
            } failure:^(NSError *error) {
                NSLog(@"网络请求错误");
            }];

        }else {
            WMESongListModel *smodel = _songArr[_index];
            NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
            [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
                NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
                NSString *strURL = result[@"songinfo"][@"lrclink"];
                [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                    
                    NSMutableArray *newArr = [NSMutableArray array];
                    for (WMEPlayerModel *model in arr) {
                        NSString *str = model.file_link;
                        [newArr addObject:str];
                    }
                    [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                    WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                    [manager downLoadWithBlock:^(BOOL have) {
                        _have = have;
                    } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                    if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                    }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                    }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                    }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                    }else {
                        [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                    }
                    _titleLabel.text = result[@"songinfo"][@"title"];
                    _authorLabel.text = result[@"songinfo"][@"author"];
                }];
            } failure:^(NSError *error) {
                NSLog(@"网络请求错误");
            }];
            
        }
    };

    ES_DefaultManager.playTimerBlock = ^(CGFloat timer){
        [self playTimer:timer];
    };

    [self createView];
    [self playerMusic];
    [self daohang];
}
- (void)createView
{
    WS(ws);
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, WIDTH)];
    [self.view addSubview:_scrollView];
    _scrollView.contentSize = CGSizeMake(WIDTH * 3, WIDTH);
    //整页翻动
    _scrollView.pagingEnabled = YES;
    //边缘弹动
    _scrollView.bounces = YES;
    _scrollView.delegate = self;
    
    self.songList = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, WIDTH)];
    _songList.delegate = self;
    _songList.dataSource = self;
    //        _songList.backgroundColor = [UIColor redColor];
    [self.scrollView addSubview:_songList];
    
    self.cover = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH + 10, 10, WIDTH - 20, WIDTH - 20)];
    //裁剪边界
    _cover.layer.masksToBounds = YES;
    //设置圆角
    _cover.layer.cornerRadius = (WIDTH - 20)/ 2.0f;
    //设置边界颜色
    _cover.layer.borderColor = [[UIColor whiteColor] CGColor];
    //设置边界宽度
    _cover.layer.borderWidth = 3.0f;
    _cover.backgroundColor = [UIColor blackColor];
//    _cover.contentMode = UIViewContentModeScaleAspectFit;
    _cover.userInteractionEnabled = YES;
    [self.scrollView addSubview:_cover];
    
    self.lyTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH * 2, 0, WIDTH, WIDTH)];
    _lyTableView.dataSource = self;
    _lyTableView.delegate = self;
    _lyTableView.separatorStyle = NO;
    _lyTableView.backgroundColor = [UIColor yellowColor];
    [self.scrollView addSubview:_lyTableView];
    [_songList registerClass:[UITableViewCell class] forCellReuseIdentifier:@"songCell"];
    [_lyTableView registerClass:[WMELyTableViewCell class] forCellReuseIdentifier:@"lyCell"];
    _scrollView.contentOffset = CGPointMake(WIDTH, 0);    NSLog(@"%@", _dic[@"songinfo"]);
    if ([_dic[@"songinfo"][@"album_1000_1000"] length]) {
        [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"album_1000_1000"]]];
    }else if ([_dic[@"songinfo"][@"album_500_500"] length]) {
        [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"album_500_500"]]];
    }else if([_dic[@"songinfo"][@"artist_640_1136"] length]) {
        [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"artist_640_1136"]]];
    }else if ([_dic[@"songinfo"][@"artist_500_500"] length]) {
        [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"artist_500_500"]]];
    }else if ([_dic[@"songinfo"][@"artist_480_800"] length]) {
        [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"artist_480_800"]]];
    }
//    [_cover sd_setImageWithURL:[NSURL URLWithString:_dic[@"songinfo"][@"album_500_500"]]];
    WMEDonut *huan = [[WMEDonut alloc] initWithFrame:CGRectMake(self.view.center.x - 45, self.view.frame.size.height - WIDTH - 180 * HEIGHTSCALE, 90 * WIDTHSCALE, 90 * WIDTHSCALE)];
    [self.view addSubview:huan];
    huan.layer.masksToBounds = YES;
    huan.layer.cornerRadius = 45;
    huan.backgroundColor = [UIColor clearColor];
    [huan.layer addAnimation:[self AlphaLight:2.5f] forKey:@"aAlpha"];
    [huan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.view.mas_left).with.offset(WIDTH/ 2 - 45);
        make.right.equalTo(ws.view.mas_right).with.offset(- (WIDTH / 2 - 45));
        make.bottom.equalTo(ws.view.mas_bottom).with.offset(-15);
        make.height.equalTo (@(90));
    }];
    
    self.play = [UIButton buttonWithType:UIButtonTypeSystem];
    //        _play.backgroundColor = [UIColor redColor];
    [_play setBackgroundImage:[UIImage imageNamed:@"noplayer"] forState:UIControlStateNormal];
    [_play addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
    //        _play.layer.masksToBounds = YES;
    //        _play.layer.cornerRadius = 42;
    [self.view addSubview:_play];
    
    self.next = [UIButton buttonWithType:UIButtonTypeSystem];
    [_next setBackgroundImage:[UIImage imageNamed:@"next"] forState:UIControlStateNormal];
//    _next.backgroundColor = [UIColor orangeColor];
    [_next addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_next];
    
    self.previous = [UIButton buttonWithType:UIButtonTypeSystem];
    [_previous setBackgroundImage:[UIImage imageNamed:@"previous"] forState:UIControlStateNormal];
//    _previous.backgroundColor = [UIColor yellowColor];
    [_previous addTarget:self action:@selector(previousAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_previous];
    
    [_play mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.left.equalTo(ws.mas_left).with.offset(WIDTH/ 2 - 42);
        //            make.right.equalTo(ws.mas_right).with.offset(- (WIDTH / 2 - 42));
        make.centerY.equalTo(@[_next, _previous]);
        make.bottom.equalTo(ws.view.mas_bottom).with.offset(-40);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [_next mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_previous mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [self.view distributeSpacingHorizontallyWith:@[_previous, _play, _next]];
    
    self.shijian = [[UISlider alloc] init];
    [self.view addSubview:_shijian];
    [_shijian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.view.mas_left).with.offset(50);
        make.right.equalTo(ws.view.mas_right).with.offset(-50);
        make.top.equalTo(ws.view.mas_top).with.offset(WIDTH + 20 + 64);
    }];
//    _shijian.minimumValue = 0;
//    self.model = _listArr[0];
//    _shijian.maximumValue = [_model.file_duration integerValue];
    [_shijian addTarget:self action:@selector(shijianAction:) forControlEvents:UIControlEventValueChanged];
    
    self.beginLabel = [[UILabel alloc] init];
    [self.view addSubview:_beginLabel];
    _beginLabel.font = [UIFont systemFontOfSize:12];
    _beginLabel.textAlignment = NSTextAlignmentCenter;
    [_beginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.view.mas_left).with.offset(0);
        make.right.equalTo(_shijian.mas_left).with.offset(0);
        make.top.equalTo(ws.view.mas_top).with.offset(WIDTH + 20 + 64);
        make.height.mas_equalTo(_shijian.mas_height);
    }];
    
    self.endLabel = [[UILabel alloc] init];
    [self.view addSubview:_endLabel];
    _endLabel.font = [UIFont systemFontOfSize:12];
    _endLabel.textAlignment = NSTextAlignmentCenter;
    [_endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_shijian.mas_right).with.offset(0);
        make.right.equalTo(ws.view.mas_right).with.offset(0);
        make.top.equalTo(ws.view.mas_top).with.offset(WIDTH + 20 + 64);
        make.height.mas_equalTo(_shijian.mas_height);
    }];
}

- (NSInteger)randomIndex{
    return arc4random()%(self.songArr.count);
}

- (void)playTimer:(CGFloat)timer{
    
    self.beginLabel.text = [NSString formatTimer:timer];
    
    self.endLabel.text = [NSString formatTimer:(ES_DefaultManager.sumTime - timer)];
    
    self.shijian.value = timer / ES_DefaultManager.sumTime;
    
    self.cover.transform = CGAffineTransformRotate(self.cover.transform, M_PI / 180);
    
    //    NSArray *timeArray = model.timerArray;
    //
    //    for (int i = 0 ; i < timeArray.count ; i++) {
    //
    //        NSString *str = [[timeArray[i] componentsSeparatedByString:@"."] firstObject];
    //
    //        if ([[NSString formatTimer:timer] isEqualToString:str]) {
    //            [self.lyricTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    //        }
    //    }
    //保持选中状态
    [self.lyTableView selectRowAtIndexPath:[self lyricTableViewTime:timer] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    
    
}
- (void)nextAction:(UIButton *)btn
{
    NSInteger playStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"playStyle"];
    if (playStyle == 2) {
        _index = [self randomIndex];
        WMESongListModel *smodel = _songArr[_index];
        NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
        [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
            NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
            NSString *strURL = result[@"songinfo"][@"lrclink"];
            [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                self.str = resultw;
                NSMutableArray *newArr = [NSMutableArray array];
                for (WMEPlayerModel *model in arr) {
                    NSString *str = model.file_link;
                    [newArr addObject:str];
                }
                [self musicModelRequest:self.str];
                [self.lyTableView reloadData];
                self.lyTableView.contentOffset = CGPointMake(0, 0);
                [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                [manager downLoadWithBlock:^(BOOL have) {
                    _have = have;
                } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }else if([result[@"songinfo"][@"album_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_640_1136"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                }else {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }
                _titleLabel.text = result[@"songinfo"][@"title"];
                _authorLabel.text = result[@"songinfo"][@"author"];
            }];
        } failure:^(NSError *error) {
            NSLog(@"网络请求错误");
        }];
    }else {
        if (_newIndex + 1 == _songArr.count) {
            _newIndex = 0;
        }else {
            _newIndex++;
        }
        WMESongListModel *smodel = _songArr[_newIndex];
        NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
        [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
            NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
            NSString *strURL = result[@"songinfo"][@"lrclink"];
            [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                self.str = resultw;
                [self musicModelRequest:self.str];
                [self.lyTableView reloadData];
                self.lyTableView.contentOffset = CGPointMake(0, 0);
                NSMutableArray *newArr = [NSMutableArray array];
                for (WMEPlayerModel *model in arr) {
                    NSString *str = model.file_link;
                    [newArr addObject:str];
                }
                [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                [manager downLoadWithBlock:^(BOOL have) {
                    _have = have;
                } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                }else {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }
                [_play setBackgroundImage:[UIImage imageNamed:@"noplayer"] forState:UIControlStateNormal];
                _titleLabel.text = result[@"songinfo"][@"title"];
                _authorLabel.text = result[@"songinfo"][@"author"];
            }];
        } failure:^(NSError *error) {
            NSLog(@"网络请求错误");
        }];
    }
}
- (void)previousAction:(UIButton *)btn
{
    NSInteger playStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"playStyle"];
    if (playStyle == 2) {
        _index = [self randomIndex];
        WMESongListModel *smodel = _songArr[_index];
        NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
        [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
            NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
            NSString *strURL = result[@"songinfo"][@"lrclink"];
            [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                self.str = resultw;
                [self musicModelRequest:self.str];
                [self.lyTableView reloadData];
                self.lyTableView.contentOffset = CGPointMake(0, 0);
                NSMutableArray *newArr = [NSMutableArray array];
                for (WMEPlayerModel *model in arr) {
                    NSString *str = model.file_link;
                    [newArr addObject:str];
                }
                [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                [manager downLoadWithBlock:^(BOOL have) {
                    _have = have;
                } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                }else {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }
                _titleLabel.text = result[@"songinfo"][@"title"];
                _authorLabel.text = result[@"songinfo"][@"author"];
            }];
        } failure:^(NSError *error) {
            NSLog(@"网络请求错误");
        }];
    }else {
        if (_newIndex - 1 == -1) {
            _newIndex = _songArr.count - 1;
        }else {
            _newIndex--;
        }
        WMESongListModel *smodel = _songArr[_newIndex];
        NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
        [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
            NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
            NSString *strURL = result[@"songinfo"][@"lrclink"];
            [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                self.str = resultw;
                [self musicModelRequest:self.str];
                [self.lyTableView reloadData];
                self.lyTableView.contentOffset = CGPointMake(0, 0);
                NSMutableArray *newArr = [NSMutableArray array];
                for (WMEPlayerModel *model in arr) {
                    NSString *str = model.file_link;
                    [newArr addObject:str];
                }
                [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
                [manager downLoadWithBlock:^(BOOL have) {
                    _have = have;
                } urlString:newArr[1] name:result[@"songinfo"][@"title"]];
                if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                }else {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }
                [_play setBackgroundImage:[UIImage imageNamed:@"noplayer"] forState:UIControlStateNormal];
                _titleLabel.text = result[@"songinfo"][@"title"];
                _authorLabel.text = result[@"songinfo"][@"author"];
            }];
        } failure:^(NSError *error) {
            NSLog(@"网络请求错误");
        }];
    }
}
- (void)daohang
{
    WS(ws);
    UIView *dhView = [[UIView alloc] init];
    [self.view addSubview:dhView];
    dhView.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];
    [dhView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(ws.view.mas_right).with.offset(0);
        make.top.equalTo(ws.view.mas_top).with.offset(0);
        make.left.equalTo(ws.view.mas_left).with.offset(0);
        make.height.equalTo(@(64));
    }];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(fanhui:) forControlEvents:UIControlEventTouchUpInside];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 46));
        make.left.equalTo(ws.view.mas_left).with.offset(10);
        make.top.equalTo(ws.view.mas_top).with.offset(20);
    }];
    self.titleLabel = [[UILabel alloc] init];
    [self.view addSubview:_titleLabel];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.font = [UIFont systemFontOfSize:15];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.view.mas_left).with.offset(70);
        make.right.equalTo(ws.view.mas_right).with.offset(-70);
        make.top.equalTo(ws.view.mas_top).with.offset(20);
        make.height.equalTo(@(30));
    }];
    _titleLabel.text = _dic[@"songinfo"][@"title"];
    
    self.authorLabel = [[UILabel alloc] init];
    [self.view addSubview:_authorLabel];
    _authorLabel.textAlignment = NSTextAlignmentCenter;
    _authorLabel.font = [UIFont systemFontOfSize:10];
    [_authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(ws.view.mas_left).with.offset(70);
        make.right.equalTo(ws.view.mas_right).with.offset(-70);
        make.top.equalTo(ws.view.mas_top).with.offset(50);
        make.height.equalTo(@(14));
    }];
    _authorLabel.text = _dic[@"songinfo"][@"author"];
    
    self.playStyle = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:_playStyle];
    [_playStyle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(35, 30));
        make.right.equalTo(ws.view.mas_right).with.offset(-10);
        make.top.equalTo(ws.view.mas_top).with.offset(30);
    }];
    [_playStyle addTarget:self action:@selector(playStyleAction:) forControlEvents:UIControlEventTouchUpInside];
    [_playStyle setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"style_%ld",[[NSUserDefaults standardUserDefaults] integerForKey:@"playStyle"]]] forState:UIControlStateNormal];
}
- (void)playerMusic
{
    if (_dataArr.count) {
        [ES_DefaultManager playingWithURL:[NSURL URLWithString:_dataArr[1]]];
        NSLog(@"%@", _dataArr[1]);
        WMEMusicDownLoadManager *manager = [WMEMusicDownLoadManager sharedManager];
        [manager downLoadWithBlock:^(BOOL have) {
            _have = have;
        } urlString:_dataArr[1] name:_dic[@"songinfo"][@"title"]];
        
        [self.lyTableView reloadData];
        self.lyTableView.contentOffset = CGPointMake(0, 0);
    }
}
- (void)playAction:(UIButton *)btn
{
    if (ES_DefaultManager.isPlay) {
        [self.play setBackgroundImage:[UIImage imageNamed:@"pppp"] forState:UIControlStateNormal];
        [ES_DefaultManager pause];
    }else{
        [self.play setBackgroundImage:[UIImage imageNamed:@"noplayer"] forState:UIControlStateNormal];
        [ES_DefaultManager play];
    }
}
#pragma mark - 呼吸灯动画
-(CABasicAnimation *) AlphaLight:(float)time
{
    CABasicAnimation *animation =[CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.fromValue = [NSNumber numberWithFloat:1.0f];
    animation.toValue = [NSNumber numberWithFloat:-0.1f];//这是透明度。
    animation.autoreverses = YES;
    animation.duration = time;
    animation.repeatCount = MAXFLOAT;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    return animation;
}
- (void)playStyleAction:(UIButton *)btn
{
    NSInteger playStyle = [[NSUserDefaults standardUserDefaults] integerForKey:@"playStyle"];
    
    switch (playStyle) {
        case 1:
            //1. 代表循序
            [self.playStyle setBackgroundImage:[UIImage imageNamed:@"style_2"] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"playStyle"];
            break;
            
        case 2:
            //2 . 代表随机
            [self.playStyle setBackgroundImage:[UIImage imageNamed:@"style_3"] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setInteger:3 forKey:@"playStyle"];
            break;
            
        case 3:
            //3. 代表单曲循环
            [self.playStyle setBackgroundImage:[UIImage imageNamed:@"style_1"] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"playStyle"];
            break;
            
        default:
            [self.playStyle setBackgroundImage:[UIImage imageNamed:@"style_1"] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"playStyle"];
            break;
    }
}
- (void)fanhui:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"返回");
    }];
}
- (void)shijianAction:(UISlider *)slider
{
    [ES_DefaultManager seekToTimer:slider.value];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _songList) {
        return _songArr.count;
    }else if (tableView == _lyTableView) {
        return _timerArray.count;
    }else{
        return 0;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _songList) {
        if (_songArr.count) {
            WMESongListModel *model = _songArr[indexPath.row];
            UITableViewCell *songCell = [_songList dequeueReusableCellWithIdentifier:@"songCell" forIndexPath:indexPath];
            songCell.textLabel.text = model.title;
            return songCell;
        }
        return nil;
    }else if (tableView == _lyTableView) {
        NSString *lyStr = _lyricArray[indexPath.row];
        WMELyTableViewCell *lyCell = [_lyTableView dequeueReusableCellWithIdentifier:@"lyCell" forIndexPath:indexPath];
        lyCell.lyLabel.text = lyStr;
        return lyCell;
    }else {
        return nil;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _songList) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        WMESongListModel *smodel = _songArr[indexPath.row];
        NSString *str = [@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.getInfos&ts=1461321078&songid=7330118&nw=2&l2p=218.9&lpb=320000&ext=MP3&format=json&from=ios&usup=1&lebo=0&aac=0&ucf=4&vid=&res=1&e=qfJshuUl8FS63N7L4gV2HAP%2FtWo%2F43nPR3pY%2FvY8iAo%3D&version=5.5.6&from=ios&channel=appstore&operator=1" stringByReplacingOccurrencesOfString:@"songid=7330118" withString:[NSString stringWithFormat:@"songid=%@", smodel.song_id]];
        [WMEAFNetworking GETNetWithUrl:str body:nil headerFile:nil response:WMEJOSN success:^(id result) {
            NSArray *arr = [WMEPlayerModel modelHandlerWithArray:result[@"songurl"][@"url"]];
            NSString *strURL = result[@"songinfo"][@"lrclink"];
            [NetwrokHandler GETWithURL:strURL completion:^(id resultw) {
                self.str = resultw;
                [self musicModelRequest:self.str];
                NSMutableArray *newArr = [NSMutableArray array];
                for (WMEPlayerModel *model in arr) {
                    NSString *str = model.file_link;
                    [newArr addObject:str];
                }
                
                [self.lyTableView reloadData];
                self.lyTableView.contentOffset = CGPointMake(0, 0);
                [ES_DefaultManager playingWithURL:[NSURL URLWithString:newArr[1]]];
                if ([result[@"songinfo"][@"album_1000_1000"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }else if ([result[@"songinfo"][@"album_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_500_500"]]];
                }else if([result[@"songinfo"][@"artist_640_1136"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_640_1136"]]];
                }else if ([result[@"songinfo"][@"artist_500_500"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_500_500"]]];
                }else if ([result[@"songinfo"][@"artist_480_800"] length]) {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"artist_480_800"]]];
                }else {
                    [_cover sd_setImageWithURL:[NSURL URLWithString:result[@"songinfo"][@"album_1000_1000"]]];
                }
                _titleLabel.text = result[@"songinfo"][@"title"];
                _authorLabel.text = result[@"songinfo"][@"author"];
            }];
        } failure:^(NSError *error) {
            NSLog(@"网络请求错误");
        }];
    }else{
        
    }
}
- (NSIndexPath*)lyricTableViewTime:(CGFloat)time{
    for (int i = 0 ; i < self.timerArray.count ; i++){
        CGFloat timeArray = [self.timerArray[i] ES_StringToTime];
        if (time < timeArray){
            return [NSIndexPath indexPathForItem:(i - 1 > 0 ? i - 1 : 0) inSection:0];
        }
    }
    return [NSIndexPath indexPathForItem:self.timerArray.count - 1 inSection:0];
}
- (void)musicModelRequest:(NSString *)str{
    //歌词和时间数组
    NSArray *arr = [str componentsSeparatedByString:@"\n"];
    //歌词时间数组
    NSMutableArray *timerMutableArray = [NSMutableArray array];
    //歌词数组
    NSMutableArray *lysicMutableArray = [NSMutableArray array];
    
    for (NSString *string in arr) {
        
        //拆分时间和歌词
        NSArray *timeAndLyric = [string componentsSeparatedByString:@"]"];
        for (NSString *temp in timeAndLyric) {
            NSLog(@"%@", temp);
        }
        //拆分时间
        NSArray *timerArray = [timeAndLyric.firstObject componentsSeparatedByString:@"["];
//        NSMutableArray *timerArray = [NSMutableArray array];
//        for (NSString *temp in timeAndLyric) {
//            if ([temp containsString:@"["]) {
//                 timerArray = [[temp componentsSeparatedByString:@"["] mutableCopy];
//            }
//        }
        //添加时间
        [timerMutableArray addObject:timerArray.lastObject];
//        [timerMutableArray arrayByAddingObjectsFromArray:timerArray];
        
        //添加歌词
        [lysicMutableArray addObject:timeAndLyric.lastObject];
    }
    self.timerArray = [NSMutableArray arrayWithArray:timerMutableArray];
    self.lyricArray = [NSMutableArray arrayWithArray:lysicMutableArray];
    
}
- (void)handleRouterChange:(NSNotification *)notification
{
    NSDictionary *info = notification.userInfo;
    AVAudioSessionRouteChangeReason reason = [info [AVAudioSessionRouteChangeReasonKey] unsignedIntValue];
    //拔掉 耳机触发 的事件
    NSLog(@"2222");
    if (reason == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
        AVAudioSessionRouteDescription *previousRoute = info[AVAudioSessionRouteChangePreviousRouteKey];
        NSLog(@"33333 ");
        AVAudioSessionPortDescription *previousOutput = previousRoute.outputs[0];
        NSString *portType = previousOutput.portType;
        
        if ([portType isEqualToString:AVAudioSessionPortHeadphones]) {
            NSLog(@"huuhu");
            [ES_DefaultManager pause];
            [self.play setBackgroundImage:[UIImage imageNamed:@"pppp"] forState:UIControlStateNormal];
        }
    }
}
//通话中断触发的事件
- (void)handleInterruption:(NSNotification *)notification
{
    //获取通知 中的用户信息
    NSDictionary *info = notification.userInfo;
    
    AVAudioSessionInterruptionType type = [info [AVAudioSessionInterruptionOptionKey] unsignedIntValue];
    if (type == AVAudioSessionInterruptionTypeBegan) {
        [ES_DefaultManager pause];
    }else {
        AVAudioSessionInterruptionOptions options = [info [AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
        if (options == AVAudioSessionInterruptionOptionShouldResume) {
            [ES_DefaultManager play];
            [self.play setBackgroundImage:[UIImage imageNamed:@"pppp"] forState:UIControlStateNormal];
        }
    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
